﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;

namespace _20160627AJAX项目学习._04JSon学习
{
    /// <summary>
    /// JSonTest 的摘要说明
    /// </summary>
    public class JSonTest : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            JavaScriptSerializer jss = new JavaScriptSerializer();      //创建JavaScriptSerializer对象jss
            string json = jss.Serialize(new Person() { Name = "蕾蕾", Age = 1 });   //jss对象调用Serialize方法将对象序列化
            context.Response.Write(json);
         }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }
}